<template>
    <div :style="{minHeight: h}" class="main">
        <header-1 class="d1">
            <template v-slot:center>
               <span class="center">
                    创建推荐活动
               </span>
            </template>
            <template v-slot:right>
               <span class="right" @click="sure">
                    保存
               </span>
            </template>
        </header-1>
        <div class="show">
            <div class="show1">
                <span>中文名称</span>
                <input class="show1_1" v-model="name" placeholder="如暑假优惠大酬宾" />
            </div>
            <div class="show1">
                <span>英文名称</span>
                <input class="show1_1" v-model="usname" placeholder="Such as Summer discount" />
            </div>
            <div class="show1">
                <span>活动日期</span>
                <div class="showm3">
                    <div class="showm3_1" @click="chose1">
                        <span>{{value}}</span>
                        <img src="https://cdn3.axureshop.com/demo/1525603/images/2%E9%97%A8%E5%BA%97%E4%BF%A1%E6%81%AF/u716.png" />
                    </div>
                </div>
            </div>
            <div class="show1">
                <span>备注说明</span>
                <input class="show1_1" v-model="money" placeholder="请输入备注" />
            </div>
        </div>
        <div class="middle">
            <p>中文海报<span>(推荐尺寸960*256)</span></p>
            <van-uploader 	 preview-size="150px" :max-count="1" v-model="fileList"  />
            <p>英文海报<span>(推荐尺寸960*256)</span></p>
            <van-uploader 	 preview-size="150px" :max-count="1" v-model="fileList1"  />
        </div>
        <van-date-picker
                    show-toolbar
                    v-model="currentDate"
					title="选择时间段"
                    :min-date="minDate"
                    :max-date="maxDate"
                    @cancel="cancel"
                    @confirm="onConfirm"
                    @change="onChange"
                    class="t1"
                    v-show="showPicker"
            >
            <template v-slot:tishi>
               <span>
                    请选择时间
               </span>
            </template>
            </van-date-picker>


            <div class="show11">
            <div class="show21">
                <span>推荐商品</span>
                <div class="showm4">
                    <div class="showm4_1" @click="add">
                        <span>添加商品{{obj.length}}/20</span>
                        <img src="https://cdn3.axureshop.com/demo/1525603/images/2%E9%97%A8%E5%BA%97%E4%BF%A1%E6%81%AF/u716.png" />
                    </div>
                </div>
            </div>
            <div v-if="obj.length" class="www">
                <p v-for="(item,index) in obj" :key="index"><span>{{item.name}}</span><span><span class="www1">₱{{item.money}}</span><span class="www2" @click="del(index)">x</span></span></p>
            </div>
        </div>
        <p class="la">温馨提示：活动审核通过后无法修改</p>
        <div class="ddddd"></div>
        <div class="search" v-show="search">
            <div class="search1">
                <p>添加商品</p>
                <van-search v-model="valuea" placeholder="请输入搜索关键词" @input="toolTipTitle" />
                <div v-for="item in arr1" :key="item.id" class="search2">
                    <div class="search3">
                        <span v-html="item.name"></span>
                        <span>{{item.money}}</span>
                    </div>
                    <div class="search4" :class="{p1 : item.state}" @click="chos(item)">
                    </div>
                </div>
                <div class="search5">
                        <div class="search6" @click="confirm">
                            取消
                        </div>
                        <div class="search7" @click="add1">
                            添加
                        </div>
                    </div>
            </div>
        </div>
    </div>
</template>
<script>
import header1 from '../../components/BS/header1View.vue'
import VanDatePicker from '../../components//BS/DoubleTimeView.vue';
import { Toast } from 'vant';
import {moni} from '../../https/MaRk'
export default {
    data(){
        return{
            h: '',
            money:'',
            name:'',
            usname:'',
            num:'',
            value:'请选择起止时间',
            showPicker: false,
            minDate: new Date(2010, 5, 15),
            maxDate: new Date(2025, 10, 15),
            currentDate: new Date(),
            startDate: '',
            endDate: '',
            fileList: [],
            fileList1: [],
            obj:[],
            valuea:'',
            arr:['王正则','牛肉面(双蛋)','米线(双蛋)','王政泽(双蛋)'],
            titleIdCodeText:'',
            arr1:[],
            search:false,
            
        }
    },
    created(){
        this.h = window.innerHeight + 'px'
    },
    components:{
        header1,
        VanDatePicker
    },
    methods:{
       sure(){
        let that = this
            moni().then(res =>{
                console.log(res);
                Toast.success({
                message:'添加成功',
                duration:1000,
                onClose(){
                    that.$router.push('/okavi26')
                }
            });
            })
       },
       add(){
        this.search = !this.search
       },
       confirm(){
        this.search = !this.search
       },
       add1(){
        this.search = !this.search
        this.arr1.forEach(item =>{
            if(item.state){
                item.name=item.name.replace("<font color=red>","");
                item.name=item.name.replace("</font>","");
                if(this.obj.length<20){
                    this.obj.push(item)
                }
            }
        })
        this.arr1 = []
        this.valuea = ''
       },
       chos(item){
        item.state = !item.state
       },
       del(index){
        this.obj.splice(index,1)
       },
          //打开时间选择器
        chose1(){
        this.showPicker = !this.showPicker
       },
       chose2(){
        this.showPicker = !this.showPicker
       },
       // 取消
       cancel(){
        this.showPicker = !this.showPicker
       },
       // 确定
        onConfirm(value, index){
            console.log(`当前值：${value}, 当前索引：${index}`)
            this.startDate = value.slice(0,3).join('-')
            this.endDate = value.slice(4,7).join('-')
            this.value = this.startDate + '至' + this.endDate
            this.showPicker = !this.showPicker
        },
        // 改变
        onChange(picker, value, index) {
            console.log(`当前值：${value}, 当前索引：${index}`)
        },
        toolTipTitle() {
            this.arr1 = []
            this.arr.forEach(item => {
                if(item.includes(this.valuea)&&this.valuea != ''){
                    this.titleIdCodeText = item
                    this.titleIdCodeText = this.titleIdCodeText.split(this.valuea).join(`<font color=red>${this.valuea}</font>`)
                     this.arr1.push({
                        name:this.titleIdCodeText,
                        state:false,
                        money:10
                     })
                }
            });
    },
    }
}
</script>
<style scoped>
.main{
    background-color: #f5f5f5;
}
.show{
    width: 100%;
    height: 255px;
    background-color: #FFFFFF;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    margin-top: 20px;
    margin-bottom: 20px;
}
.show1{
    width: 90%;
    height: 60px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 12px;
}
.show1_1{
    width: 240px;
    height: 45px;
    background-color: #f5f5f5;
    border-radius: 5px;
    border: none;
    color: #999999;
}
.showm3{
    width: 244px;
    height: 45px;
    background-color: #f5f5f5;
    border-radius: 5px;
    display: flex;
    justify-content: center;
}
.showm3_1{
    width: 90%;
    height: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: #999999;
}
.middle{
    width: 100%;
    min-height: 300px;
    background-color: #FFFFFF;
    font-size: 13px;
    display: flex;
    flex-direction: column;
    align-items: center;
}
.middle p{
    width: 90%;

}
.middle span{
    color: #999999;
}
.btn{
    width: 90%;
    height: 92px;
    background-color: #f5f5f5;
    display: flex;
    justify-content: center;
    align-items: center;
}
.show11{
    width: 100%;
    min-height: 60px;
    background-color: #FFFFFF;
    margin-top: 20px;
    margin-bottom: 20px;
    display: flex;
    flex-direction: column;
    border-bottom:1px solid #e4e4e4 ;
}
.show21{
    width: 90%;
    height: 45px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 12px;
    margin: 20px auto;
}
.showm4{
    width: 240px;
    height: 45px;
    background-color: #f5f5f5;
    border-radius: 10px;
    display: flex;
    justify-content: center;
    align-items: center;
}
.showm4_1{
    width: 90%;
    height: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: #999999;
}
.www p{
    font-size: 12px;
    width: 90%;
    margin: 10px auto;
    display: flex;
    justify-content: space-between;
}
.www1{
    color:#797979 ;
}
.www2{
    margin-left: 10px;
    font-size: 15px;
}
.la{
    width: 90%;
    font-size: 12px;
    color: #999999;
    margin: 0 auto;
}
.ddddd{
    width: 100%;
    height: 30px;
}
.search{
    position: fixed;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
}
.search1{
    width: 90%;
    height: 300px;
    background-color: #FFFFFF;
    border-radius: 10px;
    position: relative;
}
.search p{
    font-size: 17px;
    text-align: center;
}
.search2{
    font-size: 14px;
    width: 90%;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 5px;
}
.search3{
    display: flex;
    flex-direction: column;
}
.search4{
    width: 16px;
    height: 16px;
    border-radius: 50%;
    border: 1px solid #cecece;
}
.p1{
    background-color: aqua;
}
.search5{
    width: 100%;
    height: 50px;
    display: flex;
    font-size: 15px;
    position: absolute;
    bottom: 0;
}
.search6{
    width: 50%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    border-top:1px solid rgba(0, 0, 0, 0.2) ;
    border-right:1px solid rgba(0, 0, 0, 0.2) ;
}
.search7{
    width: 50%;
    height: 100%;
    color: #ff6e53;
    display: flex;
    justify-content: center;
    align-items: center;
    border-top:1px solid rgba(0, 0, 0, 0.2) ;
    border-left:1px solid rgba(0, 0, 0, 0.2) ;
}
</style>